package cn.cocho.android.mc.net;

import android.content.Context;
import android.telephony.TelephonyManager;

import cn.cocho.android.mc.storage.ApplicationCache;

/**
 * 获取手机sim相关信息的类，以及其拓展功能，如判断设备类型，是pad还是phone
 * 
 * @author hsx
 * @time 2013-5-6下午02:33:10
 */
public class SimUtils {
    
	/**
	 * 判断是否有sim卡，可以用于判断是 android-pad还是android-phone
	 *
	 * @return 
	 * @return boolean  
	 * @author hsx
	 * @time 2013-5-6上午10:27:48
	 */
	public static boolean hasSim() {
		boolean result;
		if (getSimState() == TelephonyManager.SIM_STATE_ABSENT) {
			result = false;
		} else {
			result = true;
		}
		return result;
	}

	/**
	 * 获取手机Sim卡的状态
	 * 
	 * @return 共有6种状态：<br>
	 *         第一：TelephonyManager.SIM_STATE_ABSENT（无手机sim卡）<br>
	 *         第二：TelephonyManager.SIM_STATE_NETWORK_LOCKED（需要NetworkPIN解锁）<br>
	 *         第三：TelephonyManager.SIM_STATE_PIN_REQUIRED（需要PIN解锁）<br>
	 *         第四：TelephonyManager.SIM_STATE_PUK_REQUIRED（需要PUN解锁）<br>
	 *         第五：TelephonyManager.SIM_STATE_READY（手机卡良好）<br>
	 *         第六：TelephonyManager.SIM_STATE_UNKNOWN（未知状态）<br>
	 * @return int
	 * @author hsx
	 * @time 2013-4-26下午01:58:19
	 */
	public static int getSimState() {
		TelephonyManager mTelephonyManager = (TelephonyManager) ApplicationCache.context.getSystemService(
				Context.TELEPHONY_SERVICE);
		int simState = mTelephonyManager.getSimState();
		return simState;
	}

	/**
	 * 返回sim卡的状态说明
	 * 
	 * @return 有如下几种情况：1.无卡；2.需要NetworkPIN解锁；3.需要PIN解锁；4.需要PUN解锁；5.良好；6.未知状态
	 * @return String
	 * @author hsx
	 * @time 2013-4-26下午02:22:08
	 */
	public static String getSimStateDescription() {
		int simState = getSimState();
		String mString = null;
		switch (simState) {
		case TelephonyManager.SIM_STATE_ABSENT:
			mString = "无卡";
			break;

		case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
			mString = "需要NetworkPIN解锁";
			break;

		case TelephonyManager.SIM_STATE_PIN_REQUIRED:
			mString = "需要PIN解锁";
			break;

		case TelephonyManager.SIM_STATE_PUK_REQUIRED:
			mString = "需要PUN解锁";
			break;

		case TelephonyManager.SIM_STATE_READY:
			mString = "良好";
			break;

		case TelephonyManager.SIM_STATE_UNKNOWN:
			mString = "未知状态";
			break;
		}
		return mString;
	}
}
